import os
import time
import random
import multiprocessing


def worker(msg):
    t_start = time.time()
    print('%s开始执行，进程号为%d' % (msg, os.getpid()))
    time.sleep(random.random() * 2)
    t_stop = time.time()
    print('%s执行完毕，耗时%0.2f' % (msg, t_stop - t_start))


def main():
    po = multiprocessing.Pool(3)
    for i in range(10):
        po.apply_async(worker, (i,))
    print('---start---')
    po.close()
    po.join()
    print('----end----')


if __name__ == '__main__':
    main()
